namespace TSL.Utility.Json
{
    using System;
    using System.Data;
    using System.Text;

    public class DataViewConverter : IJavaScriptConverter
    {
        public DataViewConverter()
        {
            base.m_AllowInheritance = true;
            base.m_serializableTypes = new Type[] { typeof(DataView) };
        }

        public override string Serialize(object o)
        {
            StringBuilder sb = new StringBuilder();
            this.Serialize(o, sb);
            return sb.ToString();
        }

        public override void Serialize(object o, StringBuilder sb)
        {
            DataView view = o as DataView;
            if (view == null)
            {
                throw new NotSupportedException();
            }
            new DataTableConverter().Serialize(view.ToTable(), sb);
        }
    }
}

